<template>
  <div>
    <p>{{ arr }}</p>
    <button @click="changeJoke">点击更换一个笑话</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      arr: "这是笑话",
      jokeArr: ["给爷笑", "笑吉尔", "道尔格", "南水北调","赖酱是猪"],
    };
  },
  // 目标:点击按钮随机切换笑话s
  // 1.绑定点击事件给按钮
  // 2.在事件处理函数中随机获取数组数据
  // 3.将数据赋值给arr变量
  methods: {
    changeJoke() {
      let randomIndex=parseInt(Math.random() * this.jokeArr.length)
      this.arr = this.jokeArr[randomIndex]
    },
  },
};
</script>

<style lang="scss" scoped>
</style>